package com.briup.jz.web.controller;

import com.briup.jz.bean.OrderLine;
import com.briup.jz.service.IOrderService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import com.briup.jz.vm.OrderVM;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/order")
@Api(description = "订单管理接口")
public class OrderController {
    @Autowired
    private IOrderService orderService;

    @PostMapping("commit")
    @ApiOperation("提交订单")
    public Message commit(@RequestBody OrderVM orderVM){
        orderService.commit(orderVM);
        return MessageUtil.success("提交成功");
    }

    @GetMapping("query")
    @ApiOperation("订单详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status",value = "订单状态",required = false,paramType = "query")
    })
    public Message query(String status){
        return MessageUtil.success("sucess",orderService.query(status));
    }

    @ApiOperation("查看全部订单")
    @GetMapping("findAll")
    public Message findAll() {
        orderService.findAll();
        return MessageUtil.success("sucess", orderService.findAll());


    }
    @ApiOperation("通过ID搜索订单的详细信息")
    @GetMapping("findById")
    public Message findById(long id){
   /*     orderService.findOrderDetailsById(id);*/
        return MessageUtil.success("success",orderService.findOrderDetailsById(id));

    }

    @GetMapping("payOrder")
    @ApiOperation("支付订单")
    public Message payOrder(long orderId) throws Exception{
        orderService.payOrder(orderId);
        return MessageUtil.success("成功");
    }
    @GetMapping("sendOrder")
    @ApiOperation("派单")
    public Message sendOrder(long orderId,long employeeId) throws Exception{
        orderService.sendOrder(orderId,employeeId);
        return MessageUtil.success("成功");
    }
    @GetMapping("rejectrOrder")
    @ApiOperation("服务订单")
    public Message rejectOrder(long orderId) throws Exception{
        orderService.rejectOrder(orderId);
        return MessageUtil.success("成功");
    }
    @GetMapping("confirmOrder")
    @ApiOperation("确认订单")
    public Message confirmOrder(long orderId) throws Exception{
        orderService.confirmOrder(orderId);
        return MessageUtil.success("成功");
    }


}

